<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('流程模型列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>流程名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>流程key：</label>
                                <input type="text" name="key"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="activity:MODEL:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="activity:MODEL:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
            </div>
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-fixed-columns-js"/>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('activity:MODEL:edit')}]];
        var removeFlag = [[${@permission.hasPermi('activity:MODEL:remove')}]];
        var datas = [[${@dict.getType('process_category')}]];
        var prefix = ctx + "process/model";
        var startActUrl = ctx+"activity/TASK";
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "流程模型",
                fixedColumns:true,
                fixedRightNumber:1,
                height: $(window).height()-110,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '流程ID',
                    visible: false
                },
                {
                    field: 'name',
                    title: '流程名称'
                },
                {
                    field: 'key',
                    title: '流程key'
                },
                {
                    field: 'category',
                    title: '流程分类',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                        field: 'createTime',
                        title: '创建时间'
                },
                {
                    field: 'lastUpdateTime',
                    title: '最后修改时间'
                },
                {
                    field: 'flowVersion',
                    title: '版本'
                },
                    {
                        field: 'procInstkey',
                        title: '部署流程key'
                    },
                {
                    field: 'deploymentId',
                    title: '是否部署',
                    formatter: function(value) {
                       if(value == ''||value == null || value == "null"){
                           return "否";
                       }else{
                           return "是";
                       }
                    }
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success  btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="designActivi(\''+row.id+'\')"><i class="fa fa-crop"></i>流程设计</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="deploye(\''+row.id+'\')"><i class="fa fa-delicious"></i>部署</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function designActivi(moduleId,width,height){

            //$.modal.openFull('模型设计', ctx+'modeler.html?modelId='+moduleId);

            var title= "模型设计";
            var url = ctx+'modeler.html?modelId='+moduleId;
            //$.modal.openFull("查看流程", url);
            // 如果是移动端，就使用自适应大小弹窗
            if ($.common.isMobile()) {
                width = 'auto';
                height = 'auto';
            }
            if ($.common.isEmpty(title)) {
                title = false;
            }
            if ($.common.isEmpty(url)) {
                url = "/404.html";
            }
            if ($.common.isEmpty(width)) {
                width = 800;
            }
            if ($.common.isEmpty(height)) {
                height = ($(window).height() - 50);
            }
            var index = layer.open({
                type: 2,
                area: [800 + 'px', $(window).height() - 50 + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: title,
                content: url,
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
            layer.full(index);
        }
        function deploye(moduleId){
            $.modal.confirm("确定部署该流程吗？", function() {
                var url = prefix+"/deploye"

                var data = { "modelIds": moduleId };
                $.operate.submit(url, "post", "json", data);

            });

        }

        function startProcinst(procInstkey){
            $.modal.confirm("确定启动该流程吗？", function() {
                var url = startActUrl+"/start"

                var data = { "procInstkey": procInstkey };
                $.operate.submit(url, "post", "json", data);

            });

        }

        function dealTask(procInstkey){
            $.modal.confirm("确定启动该流程吗？", function() {
                var url = startActUrl+"/deal"

                var data = { "procInstkey": "baoxiao001:2:25004" };
                $.operate.submit(url, "post", "json", data);

            });

        }

        function delDeployed(moduleId){
            $.modal.confirm("确定删除部署吗？", function() {
                var url = prefix+"/delDeployed";
                var data = { "modelIds": moduleId };
                $.operate.submit(url, "post", "json", data);

            });
        }

    </script>
</body>
</html>